package com.example.model;

import java.io.File;
import java.util.ArrayList;

/**
 * This class will keep track of an item's information, such as where they are,
 * who created it, what kind of item it is, and pictures of the item.
 * 
 * @author 3Factorial
 */
public class Item {

	private String itemName;
	private String location;
	private String description;
	private ArrayList<String> tags;
	private ArrayList<File> images;
	private User creator;
	private Date date;
	private int lost; // 0 = lost, 1 = found, 2 = donated.

	/**
	 * Creates an item with the given name, description, location, and the user
	 * that created it.
	 * 
	 * @param itemName
	 *            Item's name
	 * @param description
	 *            Item's description
	 * @param location
	 *            Item's location
	 * @param creator
	 *            Item's creator
	 */
	public Item(String itemName, String description, String location,
			User creator, Date date, int lost) {
		this.itemName = itemName;
		this.description = description;
		this.location = location;
		this.creator = creator;
		this.date = date;
		this.lost = lost;
		this.tags = new ArrayList<String>();
	} // End constructor

	/**
	 * Extra constructor for testing purposes.
	 * 
	 * @param itemName
	 *            Name this item.
	 */
	public Item(String itemName) {
		this(itemName, null, null, null, null, 0);
	}

	/**
	 * Adds the following tag to the item's tag list.
	 * 
	 * @param tag
	 *            Tag to add to item's tag list.
	 * @return
	 */
	public boolean checkTag(String tag) {
		if (tags != null) {
			return tags.contains(tag);
		} else
			return false;
	}

	/**
	 * @return 0 if lost, 1 if found, 2 if donated.
	 */
	public int isLost() {
		return lost;
	}

	@Override
	public String toString() {
		return itemName;
	}

	/**
	 * Determines whether the item matches all the filters given.
	 * 
	 * @param filters
	 *            List of all filters to check.
	 * @return True if all filters match, false if any or all do not match.
	 */
	public boolean matchesAllFilters(ArrayList<String> filters) {
		boolean matches = true;

		for (String filter : filters) {
			if (!checkTag(filter)) {
				matches = false;
			}
		}

		return matches;
	}

	/*
	 * The following are the getters and setters for this class
	 */

	/**
	 * Sets the phone status to lost (if 0), found (if 1), or donated (if 2).
	 * 
	 * @param new_status
	 *            Integer definition of item status. 0 if lost, 1 if found, or 2
	 *            if donated. Will not change the status if any other integer is
	 *            given.
	 */
	public void setStatus(int new_status) {
		if (new_status >= 0 || new_status <= 2)
			this.lost = new_status;
	}

	/**
	 * @return the itemName
	 */
	public String getItemName() {
		return itemName;
	}

	/**
	 * @param itemName
	 *            the itemName to set
	 */
	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	/**
	 * @return the location
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * @param location
	 *            the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the tags
	 */
	public ArrayList<String> getTags() {
		return tags;
	}

	/**
	 * @param tags
	 *            the tags to set
	 */
	public void setTags(ArrayList<String> tags) {
		this.tags = tags;
	}

	/**
	 * @return the images
	 */
	public ArrayList<File> getImages() {
		return images;
	}

	/**
	 * @param images
	 *            the images to set
	 */
	public void setImages(ArrayList<File> images) {
		this.images = images;
	}

	/**
	 * @return the creator
	 */
	public User getCreator() {
		return creator;
	}

	/**
	 * @param creator
	 *            the creator to set
	 */
	public void setCreator(User creator) {
		this.creator = creator;
	}

	/**
	 * @return The date the item was created
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * Adds the given tags as part of the item's tag list.
	 * 
	 * @param tag
	 *            The tag to add to this item.
	 */
	public void addTag(String tag) {
		tags.add(tag);
	}

}
